
//-----------------------------员工的vue实例------------------------------------
var user = new Vue({
    el: '#userVue',
    data: {
        //查看员工的数据定义
        //新增员工的数据定义
        userId:"",
        userName:"",
        userGender:"",
        userPosition:"",//职位
        userPhone:"",
        userAddress:"",
        userDescribe:"",
        inputUserId:"",
        inputUserName:"",
        inputUserGender:"",
        inputUserPosition:"",
        inputUserPhone:"",
        inputUserAddress:"",
        inputUserDescribe:"",
        //查看员工的数据定义
        checkedId:"",
        postCheckedId:"",
        searchTxt: '',//搜索字段
        //编辑员工的数据定义
        nowEditCol: -1, //当前编辑的行
        editStatus: false, //当前是否在编辑状态
        sortKey: '1', //排序健
        sortClass: '1', //升降排序1为升,-1为降
        //删除员工的数据定义
        userList:"",
        userListSelect:"",
        checkOneList:""
    },
    

    methods: {
       
       //查看所有员工函数     --------------------------------------checkAllUser()--------------------------------------  
        checkAllUser: function() {
             var _self = this;
            // this.postCheckedId = this.checkedId;

            $.ajax({
            type: "post",//数据发送的方式（post 或者 get）

            url: "http://localhost:8080/user/showAll",//要发送的后台地址
            data: {

            },//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
            dataType: "json",//后台处理后返回的数据格式

            success: function (data) {//ajax请求成功后触发的方法

                _self.userList=data;

            },
            error: function (msg) {//ajax请求失败后触发的方法

                    
               console.log(msg);
                  
            }
            
        });

        },
        
        //新增员工函数     --------------------------------------addUser()--------------------------------------  
        addUser: function() {
            var user;
            var userFy;
            user = this.$options.methods.form2JsonUser(); //表格的信息序列化后转json

            var userMsg= {user:user}; //把数据转成一个对象包着一个对象
            userFy = JSON.stringify(userMsg); //把要传的数据转成要求的json格式
            console.log(userFy);
            // para= decodeURIComponent(para,true);//解决中文乱码的问题

            // console.log(para);
            // para = JSON.stringify(para) ;
            // this.userId = this.inputUserId;
            // this.userName = this.inputUserName;
            // this.userGender = this.inputUserGender;
            // this.userPosition = this.inputUserPosition;
            // this.userPhone = this.inputUserPhone;
            // this.userAddress = this.inputUserAddress;
            // this.userDescribe = this.inputUserDescribe;

            $.ajax({
            type: "post",//数据发送的方式（post 或者 get）
            url: "http://localhost:8080/user/insertUser",//要发送的后台地址
            data: userFy,
                // "userId":this.userId,
                // "userName":this.userName,
                // "userGender":this.userGender,
                // "userPosition":this.userPosition,//职位
                // "userPhone":this.userPhone,
                // "userAddress":this.userAddress,
                // "userDescribe":this.userDescribe


            //要发送的数据（参数）格式为{'val1':"1","val2":"2"}
            dataType: "json",//后台处理后返回的数据格式
             contentType:"application/json",

            success: function (data) {//ajax请求成功后触发的方法
                if(data.result=="true"){
                    alert('添加成功');
                    window.location.href="http://localhost:8080/add-userIndex.html";
                }


            },
            error: function (msg) {//ajax请求失败后触发的方法

                    
               console.log(msg);

            }
        });
           
        },
    //form数据转为json数据
        form2JsonUser: function() {

            var arr = $("#addUserForm" ).serializeArray();
            var jsonStr = "";

            jsonStr += '{';
            for (var i = 0; i < arr.length; i++) {
                jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
            }
            jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
            jsonStr += '}';

            var json = JSON.parse(jsonStr);
            return json;

        },


        //查看员工函数     --------------------------------------checkUser()--------------------------------------
        checkOneUser: function(id) {
                
                var checkO = {};
                for (var i = 0, len = this.userList.length; i < len; i++) {
                    if (id === this.userList[i]['id']) {
                        checkO = this.userList[i];
                        break;
                    }
                }
                this.checkOneList = checkO;
 
                // return {
                //     'id': checkO.id,
                //     'name': checkO.name,
                //     'gender': checkO.gender,
                //     'position': checkO.position,
                //     'phone': checkO.phone,
                //     'address': checkO.address,
                //     'details': checkO.details
                // }
               // 
        },

        //编辑员工函数     --------------------------------------editUser()--------------------------------------  
        startEdit: function(id) {
                this.nowEditCol = id;
        },
        cancelEdit: function() {
                this.nowEditCol = -1;
        },
        //启动索引index数据修改确认,再把修改的数据传给后台
        sureEdit: function(id) {
                var changeMsg ={};
                for (var i = 0, len = this.userList.length; i < len; i++) {

                    if (id === this.userList[i]['id']) {
                        this.userList.splice(i, 1, this.editUser);
                        changeMsg = this.userList[i];
                        break;
                    }

                }
                this.nowEditCol = -1;   //前面为前端显示的修改
                console.log(changeMsg);

                var changeMsgFy;
                var user = {user:changeMsg};
                changeMsgFy = JSON.stringify(user);

                $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/user/updateUser",//要发送的后台地址
                data: changeMsgFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    console.log(data);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);

                }
            });
        },


        //删除员工函数     --------------------------------------deleteUser()--------------------------------------  
        deleteUser: function(id) {

            // this.postCheckedId = this.checkedId;
            console.log(id);
            var deleteMsg = {};
            for (var i = 0, len = this.userList.length; i <= len; i++) {
                    if ((id === this.userList[i]['id'])&&confirm('确认删除吗？')) {
                        deleteMsg = this.userList[i]; //在列表被删除一行之前要先把删除前的userList存进去
                        this.userList.splice(i, 1);

                        break;
                    }
                }
                console.log(this.userList);

                var deleteMsgId = deleteMsg.id;


                var deleteMsgIdStrFy ;
                var deleteMsgIdStr = {id:deleteMsgId};
                deleteMsgIdStrFy = JSON.stringify(deleteMsgIdStr);
                console.log(deleteMsgIdStrFy);

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/user/deleteUser",//要发送的后台地址
                data: deleteMsgIdStrFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    console.log(data);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);


                }
            });


        }

        
    },
    computed: {
            //存储当前编辑的对象
            editUser: function() {
                var editO = {};
                for (var i = 0, len = this.userList.length; i < len; i++) {
                    if (this.nowEditCol === this.userList[i]['id']) {
                        editO = this.userList[i];
                          break;
                    }
                }
                return {
                    'id': editO.id,
                    'name': editO.name,
                    'gender': editO.gender,
                    'position': editO.position,
                    'telephone': editO.telephone,
                    'address': editO.address
                   
                }
            }
            
        }
});

//-----------------------------供应商管理的vue实例------------------------------------
var supplier = new Vue({
    el: '#supplierVue',
    data: {
        //查看全部供应商的数据定义
        supplierList:"",
        allManager:"",
        //新增供应商的数据定义
        supplierId:"",
        supplierName:"",
        goodType:"",
        goodName:"",//职位
        goodCount:"",
        supplierContactName:"",
        supplierContactPhone:"",
        supplierDetails:"",
        inputSupplierId:"",
        inputSupplierName:"",
        inputGoodType:"",
        inputGoodName:"",
        inputGoodCount:"",
        inputSupplierContactName:"",
        inputSupplierContactPhone:"",
        inputSupplierContactDetails:"",
        //查看单个供应商的数据定义
        checkOneList:"",
        searchTxt: '',//搜索字段
        goodsListBySupplier:"",
        //编辑供应商的数据定义
        nowEditCol: -1, //当前编辑的行
        editStatus: false, //当前是否在编辑状态
        sortKey: '1', //排序健
        sortClass: '1' //升降排序1为升,-1为降
        //删除供应商的数据定义
        
        
    },
    

    methods: {
       
       //查看所有供应商函数     --------------------------------------checkAllSupplier()--------------------------------------  
        checkAllSupplier: function() {
             var _self = this;
            // this.postCheckedId = this.checkedId;

            $.ajax({
            type: "post",//数据发送的方式（post 或者 get）
            url: "http://localhost:8080/supplier/showAll",//要发送的后台地址
            data: {

            },//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
            dataType: "json",//后台处理后返回的数据格式

            success: function (data) {//ajax请求成功后触发的方法

                   //  var allSupplierMsg = {};
                   //  var goods = {};
         
                   //  for(var i= 0, len1 = data.length; i< len1; i++){
                   //       allSupplierMsg = data[i];
                   //       console.log(allSupplierMsg);
                   //  }
                    
                   //  for(var j=0, len2 = allSupplierMsg.goodsList.length;j< len2;j++){
                   //      goods = allSupplierMsg.goodsList[j];
                   //      console.log(goods);
                   
                    
                   // }
                   _self.supplierList = data;

                   var allManager = {};
                    for(var i= 0, len1 = _self.supplierList.length; i< len1; i++){
                        
                         allManager = _self.supplierList[i].manager;
                         console.log(allManager);
                         
                    }  
                    _self.allManager = allManager;
                 
                 // console.log(obj.constructor);
                 // console.log(_self.allManager);


                    
                   




            },
            error: function (msg) {//ajax请求失败后触发的方法
                 //On error do this
                    // console.info("error.");
                    // if (xhr.status == 200) {

                    //     alert(ajaxOptions);
                    // }
                    // else {
                    //     alert(xhr.status);
                    //     alert(thrownError);
                    // }
                    
               console.log(msg);
                  
            }
            
        });

        },
        
        //新增供应商函数     --------------------------------------addSupplier()--------------------------------------
        addSupplier: function() {
            var supplier;
            var supplierFy;
            supplier = this.$options.methods.form2JsonSupplier(); //表格的信息序列化后转json

            var supplierMsg= {supplier:supplier}; //把数据转成一个对象包着一个对象
            supplierFy = JSON.stringify(supplierMsg); //把要传的数据转成要求的json格式
            console.log(supplierFy);
            // para= decodeURIComponent(para,true);//解决中文乱码的问题

            // console.log(para);
            // para = JSON.stringify(para) ;
            // this.userId = this.inputUserId;
            // this.userName = this.inputUserName;
            // this.userGender = this.inputUserGender;
            // this.userPosition = this.inputUserPosition;
            // this.userPhone = this.inputUserPhone;
            // this.userAddress = this.inputUserAddress;
            // this.userDescribe = this.inputUserDescribe;

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/supplier/insertsupplier",//要发送的后台地址
                data: supplierFy,
                // "userId":this.userId,
                // "userName":this.userName,
                // "userGender":this.userGender,
                // "userPosition":this.userPosition,//职位
                // "userPhone":this.userPhone,
                // "userAddress":this.userAddress,
                // "userDescribe":this.userDescribe
                //

                //要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法
                    if(data.result=="true"){
                        alert('添加成功');
                        window.location.href="http://localhost:8080/add-supplierIndex.html";
                    }


                },
                error: function (msg) {//ajax请求失败后触发的方法


                    console.log(msg);

                }
            });

        },
        //form数据转为json数据
        form2JsonSupplier: function() {

            var arr = $("#addSupplierForm" ).serializeArray();
            var jsonStr = "";

            jsonStr += '{';
            for (var i = 0; i < arr.length; i++) {
                jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
            }
            jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
            jsonStr += '}';

            var json = JSON.parse(jsonStr);
            return json;

        },

        //查看单个供应商函数及供应商对应商品函数     --------------------------------------checkOneSupplier()--------------------------------------

        // checkOneSupplierSendId:function(supplierId){
        //     var data1 = {id:supplierId};
        //     var dataPost = JSON.stringify(data1);
        //     return dataPost;
        //     window.location.href= "http://localhost:8080/supplyGoods.html";
        // },
        //查看单个供应商函数----------------------------------------------------------------------
        checkOneSupplier: function(supplierId) {
            var _self = this;
            var checkMsgFy;
            var supplier = {id:supplierId};
            checkMsgFy = JSON.stringify(supplier);

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                async: false,
                url: "http://localhost:8080/supplier/show",//要发送的后台地址
                data: checkMsgFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    _self.checkOneList = data;
                    console.log( _self.checkOneList);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);

                }
            });
            },



            // return {
            //     'id': checkO.id,
            //     'name': checkO.name,
            //     'gender': checkO.gender,
            //     'position': checkO.position,
            //     'phone': checkO.phone,
            //     'address': checkO.address,
            //     'details': checkO.details
            // }
            //




        //供应商对应商品函数  ---------------------------------------------------------------------
        checkOneSupplierGoods: function(supplierId) {

            var _self = this;
            console.log(supplierId);

            // var oneSupplier = {};
            var data1 = {id:supplierId};
            var dataPost = JSON.stringify(data1);
            console.log(dataPost);
            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/supplier/findGoodsBysupllierID",//要发送的后台地址
                data: dataPost,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法


                    _self.goodsListBySupplier = data;

                    // console.log(_self.goodsListBySupplierId+";ier );



                },
                error: function (msg) {//ajax请求失败后触发的方法
                    // On error do this
                    // console.info("error.");
                    // if (xhr.status == 200) {
                    //
                    //     alert(ajaxOptions);
                    // }
                    // else {
                    //     alert(xhr.status);
                    //     alert(thrownError);
                    // }
                    console.log(msg);


                }
            });

                // var checkO = {};
                // for (var i = 0, len = this.userList.length; i < len; i++) {
                //     if (id === this.userList[i]['id']) {
                //         checkO = this.userList[i];
                //         break;
                //     }
                // }
                // this.checkOneList = checkO;
 
                // return {
                //     'id': checkO.id,
                //     'name': checkO.name,
                //     'gender': checkO.gender,
                //     'position': checkO.position,
                //     'phone': checkO.phone,
                //     'address': checkO.address,
                //     'details': checkO.details
                // }
               // 
        },

        //编辑供应商函数     --------------------------------------editUser()--------------------------------------  
        startEdit: function(id) {
                this.nowEditCol = id;
        },
        cancelEdit: function() {
                this.nowEditCol = -1;
        },
        //启动索引index数据修改确认
        sureEdit: function(id) {
                for (var i = 0, len = this.supplierList.length; i < len; i++) {
                    if (id === this.supplierList[i]['id']) {
                        this.supplierList.splice(i, 1, this.editSupplier);
                        break;
                    }
                }
                this.nowEditCol = -1;
        },
       

        //删除供应商函数     --------------------------------------deleteSupplier()--------------------------------------
        deleteSupplier: function(id) {

            // this.postCheckedId = this.checkedId;
            console.log(id);
            var deleteMsg = {};
            for (var i = 0, len = this.supplierList.length; i <= len; i++) {
                if ((id === this.supplierList[i]['supplierId'])&&confirm('确认删除吗？')) {
                    deleteMsg = this.supplierList[i]; //在列表被删除一行之前要先把删除前的userList存进去
                    this.supplierList.splice(i, 1);

                    break;
                }
            }
            console.log(this.supplierList);

            var deleteMsgId = deleteMsg.id;


            var deleteMsgIdStrFy ;
            var deleteMsgIdStr = {id:deleteMsgId};
            deleteMsgIdStrFy = JSON.stringify(deleteMsgIdStr);
            console.log(deleteMsgIdStrFy);

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/supplier/deletesupplier",//要发送的后台地址
                data: deleteMsgIdStrFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    console.log(data);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);


                }
            });


        }

        
    },
    computed: {
            //存储当前编辑的对象
            editSupplier: function() {
                var editO = {};
                for (var i = 0, len = this.supplierList.length; i < len; i++) {
                    if (this.nowEditCol === this.supplierList[i]['supplierId']) {
                        editO = this.supplierList[i];
                        break;
                    }
                }
                return {
                    'supplierId': editO.supplierId,
                    'supplierName': editO.supplierName,
                    'managerName': editO.manager.name,
                    'managerTelephone': editO.manager.telephone,
                    'phone': editO.phone

                   
                }
            }
            
        }
});

//-----------------------------订单的vue实例------------------------------------
var order = new Vue({
    el: '#orderVue',
    data: {
        //查看订单的数据定义
        //新增订单的数据定义
        userId:"",
        userName:"",
        userGender:"",
        userPosition:"",//职位
        userPhone:"",
        userAddress:"",
        userDescribe:"",
        inputUserId:"",
        inputUserName:"",
        inputUserGender:"",
        inputUserPosition:"",
        inputUserPhone:"",
        inputUserAddress:"",
        inputUserDescribe:"",
        //查看订单的数据定义
        checkedId:"",
        postCheckedId:"",
        searchTxt: '',//搜索字段
        //查看单个订单的数据定义
        checkOneList:"",
        goodsListByOrder:"",
        //编辑订单的数据定义
        nowEditCol: -1, //当前编辑的行
        editStatus: false, //当前是否在编辑状态
        sortKey: '1', //排序健
        sortClass: '1', //升降排序1为升,-1为降
        //删除订单的数据定义
        orderList:"",

    },


    methods: {

        //查看所有订单函数     --------------------------------------checkAllOrder()--------------------------------------
        checkAllOrder: function() {
            var _self = this;
            // this.postCheckedId = this.checkedId;

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/Order/showAll",//要发送的后台地址
                data: {

                },//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式

                success: function (data) {//ajax请求成功后触发的方法

                    // var str ='';
                    _self.orderList = data;


                },
                error: function (msg) {//ajax请求失败后触发的方法


                    console.log(msg);

                }

            });

        },

        //新增订单函数     --------------------------------------addOrder()--------------------------------------
        addOrder: function() {
            var order;
            var orderFy;
            order = this.$options.methods.form2JsonOrder(); //表格的信息序列化后转json

            var orderMsg= {userId:order}; //把数据转成一个对象包着一个对象
            orderFy = JSON.stringify(orderMsg); //把要传的数据转成要求的json格式
            console.log(orderFy);
            // para= decodeURIComponent(para,true);//解决中文乱码的问题

            // console.log(para);
            // para = JSON.stringify(para) ;
            // this.userId = this.inputUserId;
            // this.userName = this.inputUserName;
            // this.userGender = this.inputUserGender;
            // this.userPosition = this.inputUserPosition;
            // this.userPhone = this.inputUserPhone;
            // this.userAddress = this.inputUserAddress;
            // this.userDescribe = this.inputUserDescribe;

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/Order/insertOrder",//要发送的后台地址
                data: orderFy,
                // "userId":this.userId,
                // "userName":this.userName,
                // "userGender":this.userGender,
                // "userPosition":this.userPosition,//职位
                // "userPhone":this.userPhone,
                // "userAddress":this.userAddress,
                // "userDescribe":this.userDescribe
                //

                //要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法
                    if(data.result=="true"){
                        alert('添加成功');
                        window.location.href="http://localhost:8080/add-orderIndex.html";
                    }


                },
                error: function (msg) {//ajax请求失败后触发的方法


                    console.log(msg);

                }
            });

        },
        //form数据转为json数据
        form2JsonOrder: function() {

            var arr = $("#addOrderForm" ).serializeArray();
            var jsonStr = "";

            jsonStr += '{';
            for (var i = 0; i < arr.length; i++) {
                jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
            }
            jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
            jsonStr += '}';

            var json = JSON.parse(jsonStr);
            return json;

        },


        //查看订单函数及查看订单商品函数     ----------------------------------------------------------------------------
        //查看单个订单详情函数----------------------------------------------------------------------
        checkOneOrder: function(orderId) {
            var _self = this;
            var checkMsgFy;
            var order = {id:orderId};
            checkMsgFy = JSON.stringify(order);
            console.log(checkMsgFy);
            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                async: false, //同步请求，不然数据渲染会出问题
                url: "http://localhost:8080/Order/show",//要发送的后台地址
                data: checkMsgFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    _self.checkOneList = data;
                    console.log( _self.checkOneList);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);

                }
            });
        },

        //订单对应商品函数  ---------------------------------------------------------------------
        checkOneOrderGoods: function(orderId) {

            var _self = this;
            console.log(orderId);

            // var oneSupplier = {};
            var data1 = {orderId:orderId};
            var dataPost = JSON.stringify(data1);
            console.log(dataPost);
            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/Order/showAllgoods",//要发送的后台地址
                data: dataPost,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法


                    _self.goodsListByOrder = data;

                    // console.log(_self.goodsListBySupplierId+";ier );



                },
                error: function (msg) {//ajax请求失败后触发的方法
                    // On error do this
                    // console.info("error.");
                    // if (xhr.status == 200) {
                    //
                    //     alert(ajaxOptions);
                    // }
                    // else {
                    //     alert(xhr.status);
                    //     alert(thrownError);
                    // }
                    console.log(msg);


                }
            });

            // var checkO = {};
            // for (var i = 0, len = this.userList.length; i < len; i++) {
            //     if (id === this.userList[i]['id']) {
            //         checkO = this.userList[i];
            //         break;
            //     }
            // }
            // this.checkOneList = checkO;

            // return {
            //     'id': checkO.id,
            //     'name': checkO.name,
            //     'gender': checkO.gender,
            //     'position': checkO.position,
            //     'phone': checkO.phone,
            //     'address': checkO.address,
            //     'details': checkO.details
            // }
            //
        },

        //编辑订单函数     --------------------------------------editUser()--------------------------------------
        startEdit: function(id) {
            this.nowEditCol = id;
        },
        cancelEdit: function() {
            this.nowEditCol = -1;
        },
        //启动索引index数据修改确认,再把修改的数据传给后台
        sureEdit: function(id) {
            var changeMsg ={};
            for (var i = 0, len = this.userList.length; i < len; i++) {

                if (id === this.userList[i]['id']) {
                    this.userList.splice(i, 1, this.editUser);
                    changeMsg = this.userList[i];
                    break;
                }

            }
            this.nowEditCol = -1;   //前面为前端显示的修改
            console.log(changeMsg);

            var changeMsgFy;
            var user = {user:changeMsg};
            changeMsgFy = JSON.stringify(user);

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/user/updateUser",//要发送的后台地址
                data: changeMsgFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    console.log(data);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);

                }
            });
        },


        //删除订单函数     --------------------------------------deleteUser()--------------------------------------
        deleteOrder: function(id) {

            // this.postCheckedId = this.checkedId;
            console.log(id);
            var deleteMsg = {};
            for (var i = 0, len = this.orderList.length; i <= len; i++) {
                if ((id === this.orderList[i]['id'])&&confirm('确认删除吗？')) {
                    deleteMsg = this.orderList[i]; //在列表被删除一行之前要先把删除前的userList存进去
                    this.orderList.splice(i, 1);

                    break;
                }
            }
            console.log(this.orderList);

            var deleteMsgId = deleteMsg.id;


            var deleteMsgIdStrFy ;
            var deleteMsgIdStr = {id:deleteMsgId};
            deleteMsgIdStrFy = JSON.stringify(deleteMsgIdStr);
            console.log(deleteMsgIdStrFy);

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/Order/deleteOrder",//要发送的后台地址
                data: deleteMsgIdStrFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    console.log(data);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);


                }
            });


        }


    },
    computed: {
        //存储当前编辑的对象
        editUser: function() {
            var editO = {};
            for (var i = 0, len = this.userList.length; i < len; i++) {
                if (this.nowEditCol === this.userList[i]['id']) {
                    editO = this.userList[i];
                    break;
                }
            }
            return {
                'id': editO.id,
                'name': editO.name,
                'gender': editO.gender,
                'position': editO.position,
                'telephone': editO.telephone,
                'address': editO.address

            }
        }

    }
});

//-----------------------------回收站的vue实例------------------------------------
var recycle = new Vue({
    el: '#recycleVue',
    data: {

        //查看员工的数据定义

        searchTxt: '',//搜索字段
        //编辑员工的数据定义
        nowEditCol: -1, //当前编辑的行
        editStatus: false, //当前是否在编辑状态
        sortKey: '1', //排序健
        sortClass: '1', //升降排序1为升,-1为降
        userList:"",
        supplierList:"",
        orderList:"",
        checkOneList:""
    },


    methods: {

        //查看所有员工函数     --------------------------------------checkAllUser()--------------------------------------
        checkAllUser: function() {
            var _self = this;
            // this.postCheckedId = this.checkedId;

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）

                url: "http://localhost:8080/user/showAll",//要发送的后台地址
                data: {

                },//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式

                success: function (data) {//ajax请求成功后触发的方法

                    _self.userList=data;

                },
                error: function (msg) {//ajax请求失败后触发的方法


                    console.log(msg);

                }

            });

        },

        //查看所有供应商函数     --------------------------------------checkAllUser()--------------------------------------
        checkAllSupplier: function() {
            var _self = this;
            // this.postCheckedId = this.checkedId;

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）

                url: "http://localhost:8080/supplier/showAll",//要发送的后台地址
                data: {

                },//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式

                success: function (data) {//ajax请求成功后触发的方法

                    _self.supplierList=data;

                },
                error: function (msg) {//ajax请求失败后触发的方法


                    console.log(msg);

                }

            });

        },

        //查看所有订单函数     --------------------------------------checkAllUser()--------------------------------------
        checkAllOrder: function() {
            var _self = this;
            // this.postCheckedId = this.checkedId;

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）

                url: "http://localhost:8080/Order/showAll",//要发送的后台地址
                data: {

                },//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式

                success: function (data) {//ajax请求成功后触发的方法

                    _self.orderList=data;

                },
                error: function (msg) {//ajax请求失败后触发的方法


                    console.log(msg);

                }

            });

        },



        //查看员工、供应商、订单函数     ----------------------------------------------------------------------------
        checkOneUser: function(id) {

            var checkO = {};
            for (var i = 0, len = this.userList.length; i < len; i++) {
                if (id === this.userList[i]['id']) {
                    checkO = this.userList[i];
                    break;
                }
            }
            this.checkOneList = checkO;

            // return {
            //     'id': checkO.id,
            //     'name': checkO.name,
            //     'gender': checkO.gender,
            //     'position': checkO.position,
            //     'phone': checkO.phone,
            //     'address': checkO.address,
            //     'details': checkO.details
            // }
            //
        },

        checkOneSupplier: function(supplierId) {
            var _self = this;
            var checkMsgFy;
            var supplier = {id:supplierId};
            checkMsgFy = JSON.stringify(supplier);

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                async: false,
                url: "http://localhost:8080/supplier/show",//要发送的后台地址
                data: checkMsgFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    _self.checkOneList = data;
                    console.log( _self.checkOneList);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);

                }
            });
        },

        checkOneOrder: function(orderId) {
            var _self = this;
            var checkMsgFy;
            var order = {id:orderId};
            checkMsgFy = JSON.stringify(order);
            console.log(checkMsgFy);
            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                async: false, //同步请求，不然数据渲染会出问题
                url: "http://localhost:8080/Order/show",//要发送的后台地址
                data: checkMsgFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    _self.checkOneList = data;
                    console.log( _self.checkOneList);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);

                }
            });
        },


        //删除员工、供应商、订单函数     ----------------------------------------------------------------------------
        deleteUser: function(id) {

            // this.postCheckedId = this.checkedId;
            console.log(id);
            var deleteMsg = {};
            for (var i = 0, len = this.userList.length; i <= len; i++) {
                if ((id === this.userList[i]['id'])&&confirm('确认删除吗？')) {
                    deleteMsg = this.userList[i]; //在列表被删除一行之前要先把删除前的userList存进去
                    this.userList.splice(i, 1);

                    break;
                }
            }
            console.log(this.userList);

            var deleteMsgId = deleteMsg.id;


            var deleteMsgIdStrFy ;
            var deleteMsgIdStr = {id:deleteMsgId};
            deleteMsgIdStrFy = JSON.stringify(deleteMsgIdStr);
            console.log(deleteMsgIdStrFy);

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/user/deleteUser",//要发送的后台地址
                data: deleteMsgIdStrFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    console.log(data);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);


                }
            });


        },
        //删除供应商函数
        deleteSupplier: function(id) {

            // this.postCheckedId = this.checkedId;
            console.log(id);
            var deleteMsg = {};
            for (var i = 0, len = this.supplierList.length; i <= len; i++) {
                if ((id === this.supplierList[i]['supplierId'])&&confirm('确认删除吗？')) {
                    deleteMsg = this.supplierList[i]; //在列表被删除一行之前要先把删除前的userList存进去
                    this.supplierList.splice(i, 1);

                    break;
                }
            }
            console.log(this.supplierList);

            var deleteMsgId = deleteMsg.id;


            var deleteMsgIdStrFy ;
            var deleteMsgIdStr = {id:deleteMsgId};
            deleteMsgIdStrFy = JSON.stringify(deleteMsgIdStr);
            console.log(deleteMsgIdStrFy);

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/supplier/deletesupplier",//要发送的后台地址
                data: deleteMsgIdStrFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    console.log(data);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);


                }
            });


        },

        deleteOrder: function(id) {

            // this.postCheckedId = this.checkedId;
            console.log(id);
            var deleteMsg = {};
            for (var i = 0, len = this.orderList.length; i <= len; i++) {
                if ((id === this.orderList[i]['id'])&&confirm('确认删除吗？')) {
                    deleteMsg = this.orderList[i]; //在列表被删除一行之前要先把删除前的userList存进去
                    this.orderList.splice(i, 1);

                    break;
                }
            }
            console.log(this.orderList);

            var deleteMsgId = deleteMsg.id;


            var deleteMsgIdStrFy ;
            var deleteMsgIdStr = {id:deleteMsgId};
            deleteMsgIdStrFy = JSON.stringify(deleteMsgIdStr);
            console.log(deleteMsgIdStrFy);

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/Order/deleteOrder",//要发送的后台地址
                data: deleteMsgIdStrFy,//要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法

                    console.log(data);

                },
                error: function (msg) {//ajax请求失败后触发的方法

                    console.log(msg);


                }
            });


        },

        //恢复员工、供应商、订单函数     ----------------------------------------------------------------------------
        recyUser: function(id) {

            // this.postCheckedId = this.checkedId;
            console.log(id);
            var deleteMsg = {};
            for (var i = 0, len = this.userList.length; i <= len; i++) {
                if ((id === this.userList[i]['id'])&&confirm('确认恢复吗？')) {
                    deleteMsg = this.userList[i]; //在列表被删除一行之前要先把删除前的userList存进去
                    this.userList.splice(i, 1);

                    break;
                }
            }
            console.log(this.userList);




        },
        //删除供应商函数
        recySupplier: function(id) {

            // this.postCheckedId = this.checkedId;
            console.log(id);
            var deleteMsg = {};
            for (var i = 0, len = this.supplierList.length; i <= len; i++) {
                if ((id === this.supplierList[i]['supplierId'])&&confirm('确认恢复吗？')) {
                    deleteMsg = this.supplierList[i]; //在列表被删除一行之前要先把删除前的userList存进去
                    this.supplierList.splice(i, 1);

                    break;
                }
            }
            console.log(this.supplierList);


        },

        recyOrder: function(id) {

            // this.postCheckedId = this.checkedId;
            console.log(id);
            var deleteMsg = {};
            for (var i = 0, len = this.orderList.length; i <= len; i++) {
                if ((id === this.orderList[i]['id'])&&confirm('确认恢复吗？')) {
                    deleteMsg = this.orderList[i]; //在列表被删除一行之前要先把删除前的userList存进去
                    this.orderList.splice(i, 1);

                    break;
                }
            }
            console.log(this.orderList);

        }






    }
});

